
<div class="container-fluid">
    <div class="row">
        <div class="panel panel-default">
            <div class="panel-heading" style="font-weight: bold">
                <span>房屋、构筑物变动信息</span>
            </div>
            <div class="panel-body">
                <div class="form-inline" style="margin-bottom: 5px;">
                    <button class="btn btn-info btn-sm" onclick="clickSearch()">
                        <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
                        查询
                    </button>

                    <!-- Single button -->
                    <div class="btn-group">
                        <button type="button" class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            新增 <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu">
                            <li><a href="javascript:void(0);" onclick="clickAdd('51')">出租</a></li>
                            <li><a href="javascript:void(0);" onclick="clickAdd('52')">出借</a></li>
                            <li><a href="javascript:void(0);" onclick="clickAdd('53')">对外投资</a></li>
                            <li><a href="javascript:void(0);" onclick="clickAdd('54')">调拨</a></li>
                            <li><a href="javascript:void(0);" onclick="clickAdd('55')">转让</a></li>
                            <li><a href="javascript:void(0);" onclick="clickAdd('56')">置换</a></li>
                            <li><a href="javascript:void(0);" onclick="clickAdd('57')">报废</a></li>
                        </ul>
                    </div>
                    <button class="btn btn-danger btn-sm" onclick="clickDeleteAll()">批量删除</button>
                    <button class="btn btn-success btn-sm" onclick="clickAdd()">导入Excel</button>
                    <button class="btn btn-success btn-sm" onclick="clickAdd()">导出Excel</button>
                </div>

                <table id="list-table"></table>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        var h = $(window).height();
        $("#list-table").bootstrapTable({
            url:'getAlterList',
            method:'post',
            sidePagination: 'server',
            pagination:true,
            pageSize:20,
            pageList:[10,20,50],
            pageNumber:1,
            height:h - 210,
            columns:[{
                checkbox:true
            },{
                title:'变动单号',
                field:'ALTER_NO',
                sortable:true
            },{
                title:'构筑物',
                field:'BUILDING_NAME',
                sortable:true
            },{
                title:'所属单位',
                field:'COLLEGE',
                sortable:true
            },{
                title:'大楼房间号',
                field:'ROOM_NO',
                sortable:true
            },{
                title:'变动类型',
                field:'ALTERTYPE',
                sortable:true,
            },{
                title:'开始时间',
                field:'ALTER_DATE',
                sortable:true,
            },{
                title:'结束时间',
                field:'STOP_DATE',
                sortable:true,
            },{
                title:'合同号',
                field:'CONTRACT_NO',
                sortable:true,
            },{
                title:'批准文号',
                field:'PASS_NO',
                sortable:true,
            },{
                title:'批准单位',
                field:'PASS_DEPART',
                sortable:true,
            },{
                title:'批准人',
                field:'PASS_PERSON',
                sortable:true,
            },{
                title:'主管单位',
                field:'ACCEPT_HEAD_DEPART',
                sortable:true,
            },{
                title:'对方单位',
                field:'RELEVANT_DEPART',
                sortable:true,
            },{
                title:'经办人',
                field:'WORK_PERSON',
                sortable:true,
            },{
                title:'收益',
                field:'ALL_FEE',
                sortable:true,
            },{
                title:'操作',
                field:'ALTER_NO',
                halign:'center',
                align:'center',
                formatter:function (value,rowData,index) {
                    var html1 = "<button class='btn btn-xs btn-default' ALTER_NO='" + value + "' onclick='clickDetail(this)' style='margin: 2px;'>查看</button>";
                    return html1;
                }
            }],
            queryParams:function (params) {
                return params;
            },
            responseHandler:function (res) {
                console.log(res)
                return res;
            }
        });
    });


    function refreshTable() {
        $("#list-table").bootstrapTable('refresh');
    }

    function clickDetail(obj) {
        var alterNo = $(obj).attr('ALTER_NO');
        var h = $(window).height()*0.8;
        var w = $(window).width()*0.8;
        layer.open({
            title:'查看变动信息',
            area:[w + 'px', h + 'px'],
            type:2,
            content:"{:url('alterEditPage')}?alterNo=" + alterNo
        });
    }

    function clickDeleteAll() {
        var list = $("#list-table").bootstrapTable("getSelections");
        if(list.length < 1){
            layer.alert('请勾选要删除的变动',{icon:2});
            return;
        }

        var idList = [];
        for(var i = 0 ; i < list.length ; i++){
            idList.push(list[i]['ALTER_NO']);
        }
        layer.confirm('确认删除选中的变动信息吗？',{icon:3},function (index) {
            ajax("{:url('building/deleteAlter')}",{idList:idList},function (data) {
                refreshTable();
            })
        });
    }

    function clickAdd(type) {
        var h = $(window).height()*0.8;
        var w = $(window).width()*0.8;

        layer.open({
            title:'新增房屋构筑物变动',
            area:[w + 'px', h + 'px'],
            type:2,
            content:"{:url('alterAddPage')}?type=" + type
        });
    }

    function clickSearch() {
        var h = $(window).height()*0.8;
        var w = $(window).width()*0.3;
        if(w > 1200){
            w = 1200;
        }
        layer.open({
            title:'查询--请输入查询条件',
            area:[w + 'px', h + 'px'],
            type:2,
            content:"{:url('alterSearchPage')}"
        });
    }

</script>
